/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.hycreate.platform.modules.crm.project;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hycreate.platform.common.service.CrudService;
import com.hycreate.platform.modules.crm.business.CrmSysDict;
import com.hycreate.platform.modules.crm.business.Customer;
import com.hycreate.platform.modules.sys.entity.Office;
import com.hycreate.platform.modules.sys.entity.User;

/**
 * 项目管理Service
 * 
 * @author hj
 * @version 2016-12-02
 */
@Service
@Transactional(readOnly = true)
public class ProjectService extends CrudService<ProjectDao, Project> {
	@Autowired
	public ProjectDao projectDao;

	/**
	 * 查询单个项目信息
	 */
	public Project get(String id) {
		return super.get(id);
	}

	/*
	 * public List<Project> findList(Project project) { return
	 * super.findList(project); }
	 * 
	 * public Page<Project> findPage(Page<Project> page, Project project) {
	 * return super.findPage(page, project); }
	 */

	/**
	 * 查找所有项目
	 * 
	 * @return
	 */
	public List<Project> findAllProject(User user) {
		return projectDao.findAllProject(user);
	}
	/**
	 * 查询所有项目名
	 * @return
	 */
	public List<Project> findProjectName(){
		return projectDao.findProjectName();
	}

	/**
	 * 查找所有公司名
	 */
	public List<Customer> findAllCustomer() {
		return projectDao.findAllCustomer();
	}
	/**
	 * 按条件查询项目
	 * @param project
	 * @return
	 */
	public List<Project> findProject(Project project) {
		return projectDao.findProject(project);
	}

	/**
	 * 查询所有部门
	 * 
	 * @return
	 */
	public List<Office> findAllDept() {
		return projectDao.findAllDept();
	}

	/**
	 * 查询部门下的员工
	 * 
	 * @return
	 */
	public List<User> findUser(String deptId) {
		return projectDao.findUser(deptId);
	}

	/*
	 * public void changeContact(Project project){
	 * projectDao.changeContact(project); }
	 */
	/**
	 * 修改项目联系人
	 * @param project
	 */
	@Transactional(readOnly = false)
	public void changeContact(Project project) {
		if (project.getIsNewRecord()) {
			project.preInsert();
			dao.insert(project);
		} else {
			project.preUpdate();
			dao.changeContact(project);
		}
	}
	/**
	 * 查询项目所在公司的行业
	 * @param customer
	 * @return
	 */
	public List<CrmSysDict> findDict(Customer customer) {
		return projectDao.findDict(customer);
	}
	/**
	 * 修改项目状态
	 * @param projectContact
	 */
	@Transactional(readOnly = false)
	public void changeStatus(ProjectContact projectContact) {
		projectContact.preUpdate();
		dao.changeStatus(projectContact);
	}
}